/*
 *
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: Preferences.java
 *   @Date: 11/29/18 3:21 PM
 *   @Author: chenjun
 *   @Copyright（C）: 2018 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 *
 */

package io.bhex.baselib.core;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Preferences {
	private static Preferences mInstance;
	private Context mContext ;
	private SharedPreferences mPrefs;
	private static SharedPreferences.Editor mSaveEditor;
	public static final String PREFERENCE_BHEX = "bhex";



	public static Preferences getInstance(Context context) {
		if (mInstance == null)

			mInstance = new Preferences(context);

		return mInstance;
	}

	private Preferences(Context context) {
		mContext = context;
		doLoadPrefs();
	}

	public void doLoadPrefs() {

		mPrefs = mContext.getSharedPreferences(PREFERENCE_BHEX, Activity.MODE_PRIVATE);
		mSaveEditor = mPrefs.edit();

	}

	public SharedPreferences getSharePref() {
		if (mPrefs == null) {
			mPrefs = mContext.getSharedPreferences(PREFERENCE_BHEX, Activity.MODE_PRIVATE);
		}
		return mPrefs;
	}

	/**
	 * 清除Preferences的所有数据
	 * 
	 */
	public void cleanPrefs() {
		if (mPrefs == null) {
			mPrefs = mContext.getSharedPreferences(PREFERENCE_BHEX, Activity.MODE_PRIVATE);
		}
		Editor prefEditor = mPrefs.edit();
		prefEditor.clear();
//		prefEditor.commit();
		prefEditor.apply();
	}


	public void setRecordImei(String imei) {
		mSaveEditor.putString("RECORD_IMEI", imei);
//		mSaveEditor.commit();
		mSaveEditor.apply();
	}

	public String getRecordImei() {
		return mPrefs.getString("RECORD_IMEI", "");
	}

	public void setHelpEmail(String email) {
		mSaveEditor.putString("HELP_EMAIL", email);
//		mSaveEditor.commit();
		mSaveEditor.apply();
	}

	public String getHelpEmail() {
		return mPrefs.getString("HELP_EMAIL", "");
	}

}
